// ValidationAspects
// Written by Mike Saunders
// Released under Microsoft Public License (Ms-PL)
using System;
using NUnit.Framework;
using ValidationAspects.Exceptions;

namespace TestValidationAspects.Exceptions
{
	[TestFixture]
	public class TestValidateMaximumException
	{
		[SetUp]
		public void SetUp()
		{
			ValidateMaximumException.ResetMessageFormat();
		}

		[Test]
		public void Test_Constructor()
		{
			ValidateMaximumException exception = new ValidateMaximumException(1, 2);
			Assert.AreEqual(1, exception.Maximum);
			Assert.AreEqual(2, exception.Value);
		}

		[Test]
		[ExpectedException(typeof(ArgumentNullException))]
		public void Test_Constructor_throws_for_null_actual_param()
		{
			new ValidateMaximumException(1, null);
		}

		[Test]
		public void Test_default_MessageFormat()
		{
			ValidateMaximumException exception = new ValidateMaximumException(1, 2);
			Assert.AreEqual(string.Format("{0} must be less or equal to {1}", exception.GetValidationTargetName(), 1), ValidateMaximumException.MessageFormat(exception));
		}

		[Test]
		public void Test_get_Message_executes_MessageFormat()
		{
			const string message = "custom message";
			ValidateMaximumException.MessageFormat = e => message;
			Assert.AreEqual(message, new ValidateMaximumException(1, 2).Message);
		}

		[Test]
		public void Test_ResetMessageFormat()
		{
			const string message = "custom message";
			ValidateMaximumException.MessageFormat = e => message;

			ValidateMaximumException exception = new ValidateMaximumException(1, 2);
			Assert.AreEqual(message, exception.Message);

			ValidateMaximumException.ResetMessageFormat();
			Assert.AreEqual(string.Format("{0} must be less or equal to {1}", exception.GetValidationTargetName(), 1), ValidateMaximumException.MessageFormat(exception));
		}
	}
}